package cn.amebius.simpledocker.config;

import cn.amebius.simpledocker.interceptor.CustomHandshakeInterceptor;
import cn.amebius.simpledocker.websocket.*;
import cn.amebius.simpledocker.websocket.handler.ContainerLogHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;


/**
 * 描述功能： websocket配置类
 *
 * @author 阿伟
 * @date 2023/8/31 20:40
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new ConAttachSocket(),"/api/ws/attach/{key}/{containerId}")
                .addHandler(new ContainerLogHandler("容器日志socket"),"/api/ws/log/{key}/{containerId}")
                .addHandler(new ContainerStatsWebSocketHandler("容器状态socket"),"/api/ws/stats/{key}/{containerId}")
                //.addHandler(new ContainerAttachWebSocketHandler(),"/api/ws/attach/{key}/{containerId}")
                .addHandler(new ContainerTerminalWebSocketHandler(),"/api/ws/term/{key}/{containerId}")
                // WebSocket 拦截器
                .addInterceptors(new CustomHandshakeInterceptor())
                .setAllowedOrigins("*");

    }

}
